
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from rest_framework import status
from django.contrib.auth.hashers import make_password,check_password
from django.core.paginator import Paginator
from captcha.image import ImageCaptcha
from django.http import HttpResponse
from django.db.models.functions import ExtractMonth
from django.db.models import Count

from OA_django.settings import SECRET_KEY
from .utils import MyJwt
from .models import *
from .serializers import *
from .utils import jwt_auth

import re
import json
import logging
import random
import string
import redis


# 分页函数
def pag(userinfo, pag_size, pagination):
    paginator = Paginator(userinfo, pag_size)
    
    page = paginator.page(pagination)

    return page.object_list

# 递归
def recursion(carte):
    if len(carte) == 0:
        pass
    for i in carte:
        menus = MenuModel.objects.filter(menus=i['id']).order_by("menu_sort").all()
        menus = MenuSer(menus, many=True)
        menus = json.loads(json.dumps(menus.data))
        i["menus"] = recursion(menus)
    return carte

# 用户管理
class UserView(ViewSet):

    # 获取图片验证码
    def image_code(self, request):

        try:
            salt = "".join(random.sample(string.ascii_letters + string.digits, 4))
            img = ImageCaptcha()
            image = img.generate(salt)
            r = redis.Redis(host='localhost',db=0,port=6379)
            key = 'img_%s'%str(SECRET_KEY)
            r.set(key, salt, ex=60 * 5)
            return HttpResponse(image, content_type='image/png')
        except Exception as e:
            print("错误信息", e)
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "message": f"服务器错误！{e}"})

    # 校验数据
    def check_(self, mobile, password, email):
        if not re.findall(r'^1[35789]\d{9}$', mobile):
            return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '手机号格式不正确'})
        if not re.findall(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[~!@#$%^&*()_\-+])[A-Za-z\d~!@#$%^&*()_\-+]{4,16}$',
                          password):
            return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '密码是由4位到16位组成'})
        if not re.findall(r'^\w+[-_.]*[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$', email):
            return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '邮箱格式不正确'})

    # 获取ip
    def _ip(self,request):
        ip = ''
        try:
            # HTTP_X_FORWARDED_FOR: 浏览当前页面的用户计算机的网关.
            x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
            if x_forwarded_for:
                ip = x_forwarded_for.split(',')[0]
            else:
                # REMOTE_ADDR: 浏览当前页面的用户计算机的ip地址
                ip = request.META.get('REMOTE_ADDR')
        except Exception as e:
            logging.info("request user IP address failed. error msg:{}".format(e))
        return ip

    # 登录
    def login(self, request):
        name = request.data.get('name')
        mobile = request.data.get('mobile')
        password = request.data.get('password')
        image_code = request.data.get('code')

        try:
            user = UserModel.objects.filter(name=name, mobile=mobile, is_delete=0).first()
            if check_password(password, user.password):
                # 添加操作日志
                myjwt = MyJwt()
                ser = UserSer(user)

                key = 'img_%s' % str(SECRET_KEY)
                r = redis.Redis(host='localhost', db=0, port=6379)
                code = r.get(key)

                if code == None:
                    return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '图片验证码已过期'})

                if image_code.lower() != code.decode().lower():
                    return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '图片验证码不正确'})

                ip = self._ip(request)
                login_device = request.headers.get('User-Agent')
                HandleModel.objects.create(users_id=user.id, users_IP=ip, login_device=login_device,
                                           handle_url='/login', handle_action='登录', handle_step='员工登录')

                return Response({
                    'code': status.HTTP_200_OK,
                    'msg': '登录成功',
                    'token': myjwt.encode({'id': user.id}),
                    'data': ser.data,
                })
            return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '用户名或密码错误'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 获取所有信息
    @jwt_auth
    def usershow(self, request):

        name = request.data.get('name')
        mobile = request.data.get('mobile')
        station = request.data.get('station')
        pag_size = request.data.get('pag_size')
        pagination = request.data.get('pagination')

        try:
            stations = StationModel.objects.filter(is_delete=0).all()

            if station:
                stations = stations.filter(name=station, is_delete=0)

            user_list = []
            for sta in stations:
                user_set = UserModel.objects.filter(stations_id=sta.id, is_delete=0) .all()
                if name:
                    user_set = user_set.filter(name=name, is_delete=0)
                if mobile:
                    user_set = user_set.filter(mobile=mobile, is_delete=0)
                ser = UserSer(user_set,many=True)
                user_set = json.loads(json.dumps(ser.data))
                for user in user_set:
                    rank = RankModel.objects.filter(id=sta.ranks_id, is_delete=0).first()
                    section = SectionModel.objects.filter(id=sta.sections_id, is_delete=0).first()
                    role = StationRoleModel.objects.filter(station=user['stations']).first()
                    role_list = RoleModel.objects.filter(id=role.role_id).first()
                    user['rank_id']= rank.id
                    user["rank"] = rank.name
                    user["section_id"] = section.id
                    user["section"] = section.name
                    user['role'] = role_list.name
                user_list.extend(user_set)
            user_list = pag(user_list, pag_size, pagination)
            return Response({'code': status.HTTP_200_OK,'msg': '获取所有成功','data': user_list})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 获取单个信息
    @jwt_auth
    def user_desc(self, request):

        user_list = UserSer(self._cuser)
        user_lst = json.loads(json.dumps(user_list.data))

        try:
            user = UserModel.objects.filter(id=user_lst['id'], is_delete=0).first()
            station = StationModel.objects.filter(id=user.stations_id, is_delete=0).first()
            rank = RankModel.objects.filter(id=station.ranks_id, is_delete=0).first()
            section = SectionModel.objects.filter(id=station.sections_id, is_delete=0).first()
            role = StationRoleModel.objects.filter(station=station.id).first()
            role_lst = RoleModel.objects.filter(id=role.role_id).first()
            ser = UserSer(user)
            user_list = json.loads(json.dumps(ser.data))
            user_list['rank_id'] = rank.id
            user_list["rank"] = rank.name
            user_list["section_id"] = section.id
            user_list["section"] = section.name
            user_list['role'] = role_lst.name
            return Response({'code':status.HTTP_200_OK,'msg':'获取单个成功','data':user_list})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 修改员工信息
    @jwt_auth
    def upd_user(self, request):

        user_list = UserSer(self._cuser)
        user_lst = json.loads(json.dumps(user_list.data))
        name = request.data.get("name")
        mobile = request.data.get("mobile")
        account = request.data.get('account')
        password = request.data.get("password")
        email = request.data.get("email")

        try:
            flag = UserModel.objects.filter(name=name, is_delete=0).exclude(id=user_lst['id']).count()
            if flag != 0:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg": "姓名已存在！"})
            flag = UserModel.objects.filter(mobile=mobile, is_delete=0).count()
            if flag != 0:
                return Response({"code" != None: status.HTTP_400_BAD_REQUEST, "msg": "手机号已存在！"})
            flag = UserModel.objects.filter(account=account, is_delete=0).count()
            if flag != 0:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg": "账号已存在！"})
            flag = UserModel.objects.filter(email=email, is_delete=0).count()
            if flag != 0:
                return Response({"code": status.HTTP_400_BAD_REQUEST, "msg": "邮箱已存在！"})

            user = UserModel.objects.filter(id=user_lst['id']).first()
            data = UserSer(user)
            data = json.loads(json.dumps(data.data))
            data["password"] = user.password

            if name != None:
                data["name"] = name
            if mobile != None:
                data["mobile"] = mobile
            if account != None:
                data["account"] = account
            if password != None:
                hash_pwd = make_password(password)
                data["password"] = hash_pwd
            if email != None:
                data["email"] = email


            ser = UserSer(instance=user, data=data)
            if not ser.is_valid():
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': ser.errors})
            ser.save()
            return Response({'code': status.HTTP_200_OK, 'msg': '修改成功！'})

        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误！'})

    # 忘记密码
    @jwt_auth
    def forget_pwd(self,request):
        account = request.data.get('account')
        password = request.data.get('password')
        pwd = request.data.get('pwd')

        try:
            user = UserModel.objects.filter(account=account, is_delete=0)
            if not user:
                return Response({'code':status.HTTP_400_BAD_REQUEST,'msg':'此账号不存在'})

            if password != pwd:
                return Response({'code':status.HTTP_400_BAD_REQUEST,'msg':'两次输入密码不一致'})
            password = make_password(password)
            user.update(password=password)
            return Response({'code':status.HTTP_200_OK,'msg':'修改成功'})
        except Exception as e:
            print(str(e))
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg": "服务器错误！"})

# 职级管理
class RankView(ViewSet):

    # 获取所有信息
    @jwt_auth
    def rankshow(self, request):

        name = request.data.get('name')
        pag_size = request.data.get('pag_size')
        pagination = request.data.get('pagination')

        try:
            ranks = RankModel.objects.filter(is_delete=0).all()

            if name:
                ranks = ranks.filter(name=name, is_delete=0)
            ranks = pag(ranks, pag_size, pagination)

            ser = RankSer(ranks, many=True)
            return Response({'code':status.HTTP_200_OK,'msg':'获取成功','data':ser.data})
        except Exception as e:
            print(str(e))
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg": "服务器错误！"})

    # 添加职级
    @jwt_auth
    def add_rank(self, request):
        name = request.data.get('name')

        try:
            ranks = RankModel.objects.filter(name=name, is_delete=0)
            if ranks:
                return Response({'code':status.HTTP_400_BAD_REQUEST,'msg':'职级已存在，请勿重复添加'})

            rank = RankModel.objects.create(name=name)
            return Response({'code':status.HTTP_200_OK,'msg':'添加成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    # 修改职级
    @jwt_auth
    def upd_rank(self, request, pk):

        name = request.data.get('name')

        try:
            flag = RankModel.objects.filter(name=name, is_delete=0).count()
            if flag != 0:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '该职级已存在'})

            flag = RankModel.objects.filter(id=pk, is_delete=0).count()
            if flag == 0:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '该职级不存在'})

            rank = RankModel.objects.filter(id=pk)
            rank.update(name=name)
            return Response({'code':status.HTTP_200_OK,'msg':'修改成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    # 删除职级
    @jwt_auth
    def del_rank(self, request, pk):

        try:
            RankModel.objects.filter(id=pk, is_delete=0).update(is_delete=1)
            return Response({'code':status.HTTP_200_OK,'msg':'删除成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

# 部门管理
class SectionView(ViewSet):

    # 获取所有信息
    @jwt_auth
    def sectionshow(self, request):

        name = request.data.get('name')
        pag_size = request.data.get('pag_size')
        pagination = request.data.get('pagination')

        try:
            section = SectionModel.objects.filter(is_delete=0).all()

            if name:
                section = section.filter(name=name, is_delete=0)

            sections = pag(section, pag_size, pagination)

            ser = SectionSer(sections, many=True)
            return Response({'code': status.HTTP_200_OK, 'msg': '获取成功', 'data': ser.data})
        except Exception as e:
            print(str(e))
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg": "服务器错误！"})

    # 添加部门
    @jwt_auth
    def add_section(self, request):
        name = request.data.get('name')

        try:
            section = SectionModel.objects.filter(name=name, is_delete=0)
            if section:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '部门已存在，请勿重复添加'})

            section = SectionModel.objects.create(name=name)
            return Response({'code': status.HTTP_200_OK, 'msg': '添加成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 修改部门
    @jwt_auth
    def upd_section(self, request, pk):

        name = request.data.get('name')

        try:
            flag = SectionModel.objects.filter(name=name, is_delete=0)
            if flag:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '该职级已存在'})

            section = SectionModel.objects.filter(id=pk)
            section.update(name=name)
            return Response({'code': status.HTTP_200_OK, 'msg': '修改成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 删除部门
    @jwt_auth
    def del_section(self, request, pk):

        try:
            SectionModel.objects.filter(id=pk, is_delete=0).update(is_delete=1)
            return Response({'code': status.HTTP_200_OK, 'msg': '删除成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

# 职位管理
class StationView(ViewSet):

    # 获取所有信息
    @jwt_auth
    def stationshow(self, request):

        name = request.data.get('name')
        pag_size = request.data.get('pag_size')
        pagination = request.data.get('pagination')

        try:
            station = StationModel.objects.filter(is_delete=0).all()

            if name:
                station = station.filter(name=name, is_delete=0)

            station = pag(station, pag_size, pagination)
            ser = StationSer(station, many=True)
            return Response({'code': status.HTTP_200_OK, 'msg': '获取成功', 'data': ser.data})
        except Exception as e:
            print(str(e))
            return Response({"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "msg": "服务器错误！"})

    # 添加职位
    @jwt_auth
    def add_station(self, request):
        name = request.data.get('name')
        section = request.data.get('section')
        rank = request.data.get('rank')

        try:

            sections = SectionModel.objects.filter(name=section).first()
            if not sections:
                return Response({'code':status.HTTP_400_BAD_REQUEST,'msg':'该部门不存在'})
            ranks = RankModel.objects.filter(name=rank).first()
            if not ranks:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '该职级不存在'})


            station = StationModel.objects.filter(name=name, is_delete=0)
            if station:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '职位已存在，请勿重复添加'})

            section = SectionModel.objects.filter(name=section).first()
            rank = RankModel.objects.filter(name=rank).first()

            station = StationModel.objects.create(name=name,sections_id=section.id, ranks_id=rank.id)
            return Response({'code': status.HTTP_200_OK, 'msg': '添加成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 修改职位
    @jwt_auth
    def upd_station(self, request, pk):

        name = request.data.get('name')

        try:
            flag = StationModel.objects.filter(name=name, is_delete=0)
            if flag:
                return Response({'code': status.HTTP_400_BAD_REQUEST, 'msg': '该职级已存在'})

            station = StationModel.objects.filter(id=pk)
            station.update(name=name)
            return Response({'code': status.HTTP_200_OK, 'msg': '修改成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    # 删除职位
    @jwt_auth
    def del_station(self, request, pk):

        try:
            StationModel.objects.filter(id=pk, is_delete=0).update(is_delete=1)
            return Response({'code': status.HTTP_200_OK, 'msg': '删除成功'})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

# 菜单
class MenuView(ViewSet):

    @jwt_auth
    # 获取用户菜单
    def menushow(self, request):
        try:
            user = UserModel.objects.filter(id=self._cuser.id, is_delete=0).first()
            role_list = StationRoleModel.objects.filter(station_id=user.stations_id).first()
            menus = MenuRoleModel.objects.filter(role_id=role_list.role_id).all()
            menus = MenuRoleSer(menus, many=True)
            menus = json.loads(json.dumps(menus.data))
            menu_list = []
            for role in menus:

                menu = MenuModel.objects.filter(id=role['menu'], menus=None).order_by("menu_sort").all()
                menu = MenuSer(menu, many=True)
                menu = json.loads(json.dumps(menu.data))
                menu = recursion(menu)
                menu_list.extend(menu)

            return Response({'code': status.HTTP_200_OK, 'msg': '获取成功', 'data': menu_list})
        except Exception as e:
            print("错误信息", e)
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    @jwt_auth
    # 获取所有菜单
    def menu_desc(self, request):
        try:
            menu = MenuModel.objects.filter(menus=None).all()
            menu = MenuSer(menu, many=True)
            menu = json.loads(json.dumps(menu.data))

            for i in menu:
                menus = MenuModel.objects.filter(menus=i['id']).all()
                menus = MenuSer(menus, many=True)
                menus = json.loads(json.dumps(menus.data))
                i['menu_list'] = menus
            return Response({'code':status.HTTP_200_OK,'msg':'获取成功','data':menu})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})


# 操作日志
class HandleView(ViewSet):

    @jwt_auth
    # 获取所有信息
    def handleshow(self, request):

        account = request.data.get('account')
        pag_size = request.data.get('pag_size')
        pagination = request.data.get('pagination')

        try:
            handle = HandleModel.objects.all()

            if account:
                user = UserModel.objects.filter(account=account).first()
                handle = HandleModel.objects.filter(users_id=user.id).first()

            handle = pag(handle,pag_size,pagination)
            ser = HandleSer(handle, many=True)

            return Response({'code':status.HTTP_200_OK,'msg':'获取成功','data':ser.data})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

# 首页数据
class IndexView(ViewSet):

    @jwt_auth
    # 员工数据
    def user_date(self, request):

        try:
            user_num = UserModel.objects.all().count()
            official_num = UserModel.objects.filter(is_state=2).count()
            practice_num = UserModel.objects.filter(is_state=1).count()
            entry_num = UserModel.objects.filter(is_state=0).count()
            dimission_num = UserModel.objects.filter(is_state=3).count()
            positive_num = UserModel.objects.filter(is_state=4).count()

            data = {
                'user_num': user_num,
                'official_num': official_num,
                'practice_num': practice_num,
                'entry_num': entry_num,
                'dimission_num': dimission_num,
                'positive_num': positive_num,
            }

            return Response({'code':status.HTTP_200_OK,'msg':'获取成功','data':data})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    @jwt_auth
    # 员工地区分布
    def user_address(self, request):

        try:
            user = UserModel.objects.values('address').annotate(num=Count('address'))
            return Response({'code': status.HTTP_200_OK, 'msg': '获取成功', 'data': user})
        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    @jwt_auth
    # 员工生日统计
    def user_birthday(self, request):

        try:
            user = UserModel.objects.annotate(month=ExtractMonth('birthday')).values('month').annotate(num=Count('name'))
            return Response({'code':status.HTTP_200_OK,'msg':'获取成功','data':user})

        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

class MailView(ViewSet):

    @jwt_auth
    # 发送邮件
    def sendmail(self, request):
        title = request.data.get('title')
        content = request.data.get('content')
        recipient = request.data.get('recipient')
        nearby = request.data.get('nearby')

        try:
            users = UserModel.objects.filter(name=recipient).first()
            MailModel.objects.create(addresser_id=self._cuser.id, content=content, recipient_id=users.id, title=title)

            if nearby:
                mail = MailModel.objects.filter(addresser_id=self._cuser.id, content=content, recipient_id=users.id, title=title).first()
                AccessoryModel.objects.create(nearby=nearby, mails_id=mail.id)

            return Response({'code':status.HTTP_200_OK,'msg':'发送邮件成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    @jwt_auth
    # 接收邮件
    def mailshow(self, request):
        try:
            mail = MailModel.objects.filter(recipient_id=self._cuser.id, is_delete=False).all()
            mail = MailSer(mail, many=True)
            mail = json.loads(json.dumps(mail.data))

            for i in mail:
                nearby = AccessoryModel.objects.filter(mails_id=i['id']).all()
                nearby = AccessorySer(nearby, many=True)
                nearby = json.loads(json.dumps(nearby.data))
                i['nearby'] = nearby

            return Response({'code':status.HTTP_200_OK,'msg':'接收成功','data':mail})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    @jwt_auth
    # 获取垃圾箱数据
    def dustbinshow(self, request):
        try:
            mail = MailModel.objects.filter(recipient_id=self._cuser.id, is_delete=True).all()
            mail = MailSer(mail, many=True)
            mail = json.loads(json.dumps(mail.data))

            for i in mail:
                nearby = AccessoryModel.objects.filter(mails_id=i['id']).all()
                nearby = AccessorySer(nearby, many=True)
                nearby = json.loads(json.dumps(nearby.data))
                i['nearby'] = nearby

            return Response({'code': status.HTTP_200_OK, 'msg': '接收成功', 'data': mail})

        except Exception as e:
            print(str(e))
            return Response({'code': status.HTTP_500_INTERNAL_SERVER_ERROR, 'msg': '服务器错误'})

    @jwt_auth
    # 删除邮件
    def del_mail(self, request, pk):

        try:
            MailModel.objects.filter(id=pk, is_delete=False).update(is_delete=True)
            return Response({'code':status.HTTP_200_OK,'msg':'删除成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})

    @jwt_auth
    # 彻底删除
    def thorough_del(self,request, pk):

        try:
            MailModel.objects.filter(id=pk, is_delete=True).delete()
            return Response({'code':status.HTTP_200_OK,'msg':'删除成功'})
        except Exception as e:
            print(str(e))
            return Response({'code':status.HTTP_500_INTERNAL_SERVER_ERROR,'msg':'服务器错误'})







